<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>导入学生信息</title>
    <link rel="stylesheet" th:href="@{/lib/layui-v2.6.3/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/layuimini.css?v=2.0.4.2}" media="all">
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all">
    <style type="text/css">
       #test10{
           margin-left: 400px;
           width: 400px;
           height: 210px;
       }
       #test10 i{
           font-size: 100px;
       }
        #test10 p{
            font-size: 20px;
            margin-top: 5px;
            font-weight: bold;
            color:black;
        }
        #test11{
            margin-left: 400px;
            margin-top: 100px;
        }
    </style>
</head>
<body>
<div class="layui-form-item" id="test11">
    <label class="layui-form-label" style="color: red;font-weight: bold;font-size: 18px">课程名称</label>
    <div class="layui-input-inline">
        <input type="text" id="cname" name="title" required  lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
    </div>
</div>
<div class="layui-upload-drag" id="test10">
    <i class="layui-icon"></i>
    <p>点击上传，或将文件拖拽到此处</p>
    <div class="layui-hide" id="uploadDemoView">
        <hr >
        <img src="" alt="上传成功后渲染" style="max-width: 196px">
    </div>
</div>

<script th:src="@{/lib/layui-v2.6.3/layui.js}" charset="utf-8"></script>
<script th:src="@{/js/lay-config.js?v=2.0.0}" charset="utf-8"></script>
<script>
    layui.use(['upload', 'element', 'layer'],function () {
        var $ = layui.jquery
            ,upload = layui.upload
            ,element = layui.element
            ,layer = layui.layer;

        //拖拽上传
        upload.render({
            elem: '#test10',
            accept:'file',
            exts:'xls|xlsx', //只允许上传Excel文件
            url: '/importexcel',  //importexcel接口实现读取Excel文件到数据库
            before:function(obj){
                let cname=document.getElementById("cname").value;
                this.data={"cname":cname};
            },
            done: function(res){
                console.log(document.getElementById("cname").value)
                if(res.code==0){
                    layer.open({
                        title:'提示',
                        content:"<p>导入成功！快去<span style='color: red'>查看学生</span>模块查看吧</p>",
                        yes: function(index, layero){
                            layer.close(index);
                            window.location.reload();
                        }
                    });
                }else if(res.code==400){
                    layer.msg(res.message, {
                        icon: 2,
                        anim: 6
                    });
                }else if(res.code==401){
                    layer.msg(res.message, {
                        icon: 2,
                        anim: 6
                    });
                }else if(res.code==402){
                    layer.msg(res.message, {
                        icon: 2,
                        anim: 6
                    });
                }else {
                    layer.msg("导入失败！", {
                        icon: 2,
                        anim: 6
                    });
                }
            }
        });
    });
</script>
</body>
</html>